package study.optional.filter;

import study.optional.公共类.Car;
import study.optional.公共类.Insurance;
import study.optional.公共类.User;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Author 刘伟涛
 * @Date 2023/6/30 17:08
 **/
public class Demo01 {
    public static void main(String[] args) {
        Optional<Insurance> optInsurance = Optional.ofNullable(new Insurance("检测的保险名"));
        optInsurance.filter(x->"检测的保险名".equals(x.getName()))
                .ifPresent(System.out::println);

/*
        List<User> userList = Arrays.asList(new User(Optional.ofNullable(new Car(Optional.ofNullable(new Insurance("保险"))))), new User());
        Optional<List<User>> optUserList = Optional.ofNullable(userList);
        optUserList.filter(x->x.stream().filter(y->{return "保险".equals(y.getCar().flatMap(Car::getInsurance).map(Insurance::getName).orElse("没有"))).collect(Collectors.toList())}).ifPresent(x-> System.out.println("对咯"));
*/
    }
}
